<?php

class nhomtt extends database
{
    protected $_ten_ntt;
	protected $_parent;
    
    public function __construct()
    {
        $this->connection();
    }
    
    public function setTen_ntt($ntt)
    {
        $this->_ten_ntt = $ntt;
    }
    
    public function getTen_ntt()
    {
        return $this->_ten_ntt;
    }
    
	 public function setParent($parent)
    {
        $this->_parent = $parent;
    }
    
    public function getParent()
    {
        return $this->_parent;
    }
    
	
    function get_auto_increment()
    {
        $sql = "SHOW TABLE STATUS WHERE name = 'nhom_tin_tuc'";
        $this->query($sql);
        if ($this->num_rows() != 0) {
            $row = $this->fetch();
            
            return $row['Auto_increment'];
        } else {
            return FALSE;
        }
    }
    
    public function insert_nhomtt()
    {
        $sql = "INSERT INTO nhom_tin_tuc(ten_ntt, parent) VALUES('" . $this->getTen_ntt() . "','" . $this->getParent() . "' )";
        $this->query($sql);
    }
	
	public function get_parent($id, $data = array())
    {
		if(!$data) { $data = array();}
        $sql = "SELECT * FROM nhom_tin_tuc WHERE parent = '".$id."' ORDER BY id DESC";
        $this->query($sql);
        if ($this->num_rows() != 0) {
            while ($row = $this->fetch()) {
                $data[] = array(
							'id' => $row['id'],
							'ten_ntt'=> $row['ten_ntt'], 
							'parent' => $row['parent']);
				$data = $this->get_parent($row['id'], $data);
            }
            return $data;
        } else {
            return FALSE;
        }
    }
}

?>